package com.member.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.member.common.core.domain.model.LoginUser;
import com.member.common.enums.ImportFailEnum;
import com.member.shop.domain.SysBizImportFail;
import com.member.shop.domain.SysBizImportFailRegister;
import com.member.shop.mapper.SysBizImportFailMapper;
import com.member.shop.service.ISysBizImportFailService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

import static com.member.common.utils.SecurityUtils.getLoginUser;

/**
 * 导入失败Service业务层处理
 *
 * @author lixinchen
 * @date 2024-01-17
 */
@Service
public class SysBizImportFailServiceImpl extends ServiceImpl<SysBizImportFailMapper, SysBizImportFail> implements ISysBizImportFailService {
    @Resource
    private SysBizImportFailMapper sysBizImportFailMapper;

    /**
     * 查询导入失败
     *
     * @param id 导入失败主键
     * @return 导入失败
     */
    @Override
    public SysBizImportFail selectSysBizImportFailById(Long id) {
        return sysBizImportFailMapper.selectById(id);
    }

    /**
     * 查询导入失败列表
     *
     * @param sysBizImportFail 导入失败
     * @return 导入失败
     */
    @Override
    public List<SysBizImportFail> selectSysBizImportFailList(LambdaQueryWrapper<SysBizImportFail> queryWrapper) {
        return sysBizImportFailMapper.selectList(queryWrapper);
    }

    /**
     * 新增导入失败
     *
     * @param sysBizImportFail 导入失败
     * @return 结果
     */
    @Override
    public int insertSysBizImportFail(SysBizImportFail sysBizImportFail) {
        return sysBizImportFailMapper.insert(sysBizImportFail);
    }

    /**
     * 修改导入失败
     *
     * @param sysBizImportFail 导入失败
     * @return 结果
     */
    @Override
    public int updateSysBizImportFail(SysBizImportFail sysBizImportFail) {
        return sysBizImportFailMapper.updateById(sysBizImportFail);
    }

    /**
     * 批量删除导入失败
     *
     * @param ids 需要删除的导入失败主键
     * @return 结果
     */
    @Override
    public int deleteSysBizImportFailByIds(Integer type) {
        LoginUser loginUser = getLoginUser();
        LambdaQueryWrapper<SysBizImportFail> queryWrapper = new LambdaQueryWrapper<SysBizImportFail>();
        queryWrapper.eq(SysBizImportFail::getUserId,loginUser.getUserId());
        if(type==ImportFailEnum.REGISTER_MEMBER_IMPORT.getKey()){
            queryWrapper.eq(SysBizImportFail::getType, ImportFailEnum.REGISTER_MEMBER_IMPORT.getKey());
        }
        if(type==ImportFailEnum.RECHARGE_IMPORT.getKey()){
            queryWrapper.eq(SysBizImportFail::getType, ImportFailEnum.RECHARGE_IMPORT.getKey());
        }
        if(type==ImportFailEnum.ORDER_SHIPPING.getKey()){
            queryWrapper.eq(SysBizImportFail::getType, ImportFailEnum.ORDER_SHIPPING.getKey());
        }

        return sysBizImportFailMapper.delete(queryWrapper);
    }

    /**
     * 删除导入失败信息
     *
     * @param id 导入失败主键
     * @return 结果
     */
    @Override
    public int deleteSysBizImportFailById(Long id) {
        return sysBizImportFailMapper.deleteById(id);
    }


}
